using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Reflection;
using System.IO;
using System.Configuration;
using Midas.Core;
using System.Threading;

namespace Midas.Server
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.Out.WriteLine("Server Started at " + DateTime.Now.ToString("s"));
			DatabaseManager.InitialRootAdminPass = ConfigurationManager.AppSettings["InitialRootAdminPass"];
			try
			{
				MidasLogManager.RegisterListeners(ConfigurationManager.AppSettings["LogOutputs"]);
			}
			catch (Exception)
			{
			}
			try
			{
				MidasLogManager.DebugLevel = int.Parse(ConfigurationManager.AppSettings["DebugLevel"]);
			}
			catch (Exception) { }
			MidasUtility.ReadConfiguration(typeof(Program));
			Console.Out.WriteLine("Total users: " + DatabaseManager.GetNumberOfInstances<User>());
			Console.Out.WriteLine("Number of Admins: " + DatabaseManager.GetNumberOfInstances<Admin>());
			Console.Out.WriteLine("Number of Boards: " + DatabaseManager.GetNumberOfInstances<Board>());
			Console.Out.WriteLine("Number of Judges: " + DatabaseManager.GetNumberOfInstances<Judge>());
			Console.Out.WriteLine("Number of Teams: " + DatabaseManager.GetNumberOfInstances<Team>());
			Type p = typeof(Program);
			lock (p)
			{
				Monitor.Wait(p);
			}
		}
	}
}
